/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package entidade;

import controlo.util.Conexao;
import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.Statement;
import java.util.LinkedList;
import java.util.List;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.faces.model.SelectItem;

/**
 *
 * @author Lomanda
 */
public class TipoContaDAO
{
    Connection conn;
    List<SelectItem> listaTipoConta = new LinkedList<SelectItem>();

    public TipoContaDAO()
    {
        try
        {
            conn = Conexao.getConnection();
        } catch (Exception ex) {
            Logger.getLogger(ContaDAO.class.getName()).log(Level.SEVERE, null, ex);
        }
    }
    
    public List<SelectItem> contasDependentes(int moeda) throws Exception
    {
         String h;
        
         try
         {
            conn = Conexao.getConnection();
            Statement stm = conn.createStatement();
            listaTipoConta = new LinkedList<SelectItem>();
            listaTipoConta.add(new SelectItem( null ,"---"));
           // listaTipoConta.get(0).setDisabled(true);
            //listaTipoConta.get(0).setNoSelectionOption(true);
            
            ResultSet res = stm.executeQuery("SELECT DISTINCT tc.* "
                    + " FROM tipo_conta as tc,conta as c,conta_moeda as cm"
                    + " WHERE tc.idTipoConta=c.idTipoConta"
                    + " AND c.idConta=cm.idConta"
                    + " AND cm.idMoeda="+ moeda);

            while(res.next())
            {
                h = res.getString("nomeTipoConta");
                listaTipoConta.add(new SelectItem(res.getInt("idTipoConta"),h));
            }

            res.close();
            stm.close();
         }
         catch(Exception e)
         {
             e.printStackTrace();
         }

         return listaTipoConta;
    }

    public List<SelectItem> getListaTipoConta() {
        return listaTipoConta;
    }

    public void setListaTipoConta(List<SelectItem> listaTipoConta) {
        this.listaTipoConta = listaTipoConta;
    }  
}
